﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using AGrandVenture;

namespace DataEditor
{
    public partial class Form1 : Form
    {
        public bool hasStats = false;
        public bool hasRaces = false;

        public List<Stat> gameStats;
        public List<Race> gameRaces;
        

       


        public Form1()
        {
            InitializeComponent();
            txtXMLDataPath.Text = (@"XML\");
        }

        private void newStatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StatForm statForm = new StatForm(this);
            statForm.Show();
        }

        private void nPCToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }

        private void racesToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
        {
            if (this.hasStats)
                newRaceToolStripMenuItem.Enabled = true;
            else
                newRaceToolStripMenuItem.Enabled = false;
        }

        private void newRaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RaceForm raceForm = new RaceForm(this, gameStats);
            raceForm.Show();
        }

        private void btnLoadGameData_Click(object sender, EventArgs e)
        {
            #region Load Stats
            //Load Stats
            string path = Application.StartupPath + @"\" + txtXMLDataPath.Text + "stats";
            string[] files = Directory.GetFiles(path);

            if (gameStats == null)
                gameStats = new List<Stat>();

            gameStats.Clear();

            foreach (string file in files)
            {
                Stat stat = GlobalFunctions.LoadStat(file);
                gameStats.Add(stat);
            }

            lstGameStats.Items.Clear();

            foreach (Stat stat in gameStats)
            {
                lstGameStats.Items.Add(stat.Name);
            }

            if (lstGameStats != null)
                hasStats = true;
            /////
            #endregion

            #region Load Races
            //Load Races
            path = "";
            path = Application.StartupPath + @"\" + txtXMLDataPath.Text + "races";

            Array.Clear(files, 0, files.Length);
            files = Directory.GetFiles(path);

            if (gameRaces == null)
                gameRaces = new List<Race>();

            gameRaces.Clear();

            foreach (string file in files)
            {
                Race race = GlobalFunctions.LoadRace(file);
                gameRaces.Add(race);
            }

            lstGameRaces.Items.Clear();

            foreach (Race race in gameRaces)
            {
                lstGameRaces.Items.Add(race.Name);
            }

            if (lstGameRaces != null)
                hasRaces = true;
            ///
            #endregion



        }

        
    }
}
